define(function(require, exports, module) {
    var router = require("router");

    //var app = require("app");
    var controller = {};
    controller.vue = function() {
        controller.vm = new Vue({
            router: router,
            data: function() {
                return {
                    items: {},
                    user_info: {
                        tenement_type:[]
                    },
                    user_id: 0,
                    userStatistics: {},
                    mounted: 0,
                    out_room_id:0,
                    community_id:0,

                };
            },
            el: "#pageUserIndex",
            created: function created() {

                this.fetchData();
                var _this = this;
            },

            mounted: function mounted() {
                var _this = this;
                if (_this.mounted == 1) {
                    return;
                }
                $("#pageUserIndex").on("pageShow", function(e, params) {
                    _this.user_info = app.getUserInfo();
                });
                this.mounted = 1;
            },
            methods: {
                 changePhone:function(){
                app.bindPhone();
            },
                contactUs: function contactUs(e) {
                    var params = [ {
                        text: '<a href="tel://' + this.user_info.community.hotline + '">拨打电话</a>'
                    } ];
                    app.handle(params);
                },
                fetchData: function fetchData() {
                    var _this = this;
                    this.getUserInfo();
                    // _this.user_info = app.getUserInfo();
                },
                changeShopId:function(){
                    var that = this;
                    app.component("get_shop_id",{
                         title:'请选择小区',
                         type:'tenement',
                         success:function(shop_id){
                             that.$router.push({name:"index",params:{community_id:shop_id}});
                         }
                      });
                },
                getUserInfo:function(){
                    var that = this;
                    app.get("/api/user/info",{
                        fields:"user_id,store_id,phone,nickname,phone,avatarUrl,last_update_time,community,community.bills_count,topic_count,waitingpay,tenement_type,community_count,out_room_id"
                    },function(res){
                         if(res.code==200){
                             that.user_info = res.data;
                             that.out_room_id = res.data.out_room_id;
                         }
                        
                    });
                }

            }
        }).$mount("#app");
    };
    module.exports = controller;
});
